package hot100;

public class Lc35 {
    public int searchInsert(int[] nums, int target) {
        int left = -1;
        int right = nums.length;
        while (left + 1 < right) {
            int mid = (right - left) / 2 + left;
            if (nums[mid] < target) {
                left = mid;
            }
            else if (nums[mid] > target) {
                right = mid;
            }
            else {
                return mid;
            }
        }
        return right;
    }
}
